<template>
  <div class="app-container">
    <el-form
      ref="listFilterRef"
      :model="list.filter"
      inline
      class="list-filter"
    >
      <el-form-item prop="countryName">
        <el-input v-model="list.filter.countryName" placeholder="乡村名称">
          <i slot="prefix" class="el-input__icon el-icon-search" />
        </el-input>
      </el-form-item>
      <el-form-item prop="countryPlace">
        <RegionSelect
          v-model="list.filter.countryPlace"
          :props="{ checkStrictly: true }"
        />
      </el-form-item>
      <el-form-item prop="status">
        <Status v-model="list.filter.status" />
      </el-form-item>
      <el-form-item>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="table-operation">
      <AuthButton @click="c" name="新增" />
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column label="名称" prop="countryName" />
      <el-table-column label="所属地点" prop="countryPlaceSmall">
        <template slot-scope="{ row }">
          {{ row.countryPlaceSmall + row.countryPlacePlus }}
        </template>
      </el-table-column>
      <el-table-column label="简介" prop="description" />
      <el-table-column label="启用状态" width="80" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding">
        <template slot-scope="{ row: rowData }">
          <auth-button @click="u(rowData)" name="编辑" />
          <auth-button @click="d(rowData)" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
      :loading="form.loading"
    >
      <template #el-form>
        <el-form-item label="名称" prop="countryName" verify>
          <el-input
            v-model="form.data.countryName"
            maxlength="30"
            show-word-limit
            clearable
            placeholder="请输入名称"
          />
        </el-form-item>
        <el-form-item label="类型" prop="type" verify>
          <KiSelect
            v-model="form.data.type"
            :options="dict.country_type.filter((t) => t.dataName == '乡村游')"
            placeholder="类型"
            disabled
          />
        </el-form-item>
        <el-form-item label="所属地点" prop="countryPlace" verify>
          <RegionSelect v-model="form.data.countryPlace" ref="RegionSelect" />
        </el-form-item>
        <el-form-item
          label="详细地址"
          prop="countryPlacePlus"
          :verify="{ maxLength: 100 }"
        >
          <div style="display: flex; justify-content: space-between">
            <el-input
              v-model="form.data.countryPlacePlus"
              style="width: 100%"
              clearable
            >
              <el-button slot="append" @click="showCoordPicker = true">
                地图选点
              </el-button>
            </el-input>
            <CoordPicker
              :show.sync="showCoordPicker"
              :lng.sync="form.data.longitude"
              :lat.sync="form.data.latitude"
              :address.sync="form.data.countryPlacePlus"
              :city="
                $refs.RegionSelect &&
                $refs.RegionSelect.label &&
                $refs.RegionSelect.label.split('/')[0]
              "
            />
          </div>
        </el-form-item>
        <el-form-item label label-width="0">
          <el-col :span="12">
            <el-form-item label="经度" prop="longitude" verify>
              <el-input v-model="form.data.longitude" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="纬度" prop="latitude" verify>
              <el-input v-model="form.data.latitude" clearable />
            </el-form-item>
          </el-col>
        </el-form-item>
        <el-form-item label="简介" prop="description">
          <el-input
            v-model="form.data.description"
            maxlength="30"
            show-word-limit
            clearable
          />
        </el-form-item>
        <el-form-item label="封面图片" prop="avatar" verify>
          <Imgpond
            v-model="form.data.avatar"
            value-type="string"
            :count="1"
            aspectRatio="140/110"
          />
        </el-form-item>
        <el-form-item label="图片列表" prop="pictureList">
          <Imgpond
            v-model="form.data.pictureList"
            value-type="array"
            aspectRatio="140/110"
          />
        </el-form-item>
        <el-form-item label="前往路线" prop="countryWay">
          <el-input
            type="textarea"
            :autosize="{ minRows: 3 }"
            placeholder="请输入内容"
            v-model="form.data.countryWay"
            maxlength="500"
            show-word-limit
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="详细介绍" prop="descriptionPlus" verify>
          <el-input
            v-model="form.data.descriptionPlus"
            type="textarea"
            maxlength="1000"
            show-word-limit
            clearable
            placeholder="请输入详细介绍"
          ></el-input>
        </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'

export default {
  mixins: [pageMixin],
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'one-travel-api/country',
      list: {
        filter: {
          type: '01'
        }
      },
      form: {
        data: {
          status: 1,
          type: '01'
        }
      }
    }),
  data() {
    return {
      showCoordPicker: false
    }
  },
  methods: {}
}
</script>

<style lang="scss" scoped></style>
